package com.xinqi.common.core.utils;

import com.xinqi.common.base.utils.RandomUtils;

import java.util.Objects;

/**
 * MD5Hash加密解密
 *
 * @author dzy
 */
public class Md5HashUtil {

    public static String randomSalt() {
        String salt = RandomUtils.randomStr(6);
        return salt;
    }

    public static String encryptPwd(String salt, String password) {
        return Md5Utils.hash(salt + password);
    }

    public static String encryptPwdMobile(String mobile, String salt, String password) {
        return Md5Utils.hash(mobile + salt + password);
    }

    public static boolean checkPwd(String salt, String password, String hashStr) {
        String hashPwd = Md5Utils.hash(salt + password);
        return Objects.equals(hashStr, hashPwd);
    }

    public static boolean checkPwdMobile(String mobile, String salt, String password, String hashStr) {
        String hashPwd = Md5Utils.hash(mobile + salt + password);
        return Objects.equals(hashStr, hashPwd);
    }

}
